#! /bin/sh
NOSE="/usr/bin/nosetests"
SRC="Your source path"
declare -A MODULE
MODULE=(
    [module_name]="${SRC}/test_source ${SRC}/module_source"
)

check_module() {
    if [[ -z $1 ]]; then
        echo "No module specify" >&2
        exit 1
    fi
    if [[ -z ${MODULE[$1]} ]]; then
        echo "Unknown module "$1 >&2
        exit 1
    fi
}

test() {
    local p t c
    p=(${MODULE[$1]})
    if [[ -z $2 ]]; then
        t=${p[0]}
    else
        t=$2
    fi
    if [[ -z $3 ]]; then
        c=${p[1]}
    else
        t=$3
    fi
    #echo "Test $t coverage $c"
    $NOSE --with-coverage --cover-package=$c --cover-erase --cover-branches $t -s --cover-html --cover-html-dir=/var/www/html/
}

case $1 in
    "-h")
        echo "Usage: ut [-m][-lt][-lc] [module name] [test path] [coverage path]"
        echo "    -m:"
        echo "        Show support test module"
        echo
        echo "    -lt:"
        echo "        List module test source path"
        echo
        echo "    -lc:"
        echo "        List module coverage source path"
        echo "Copyright: Chensi.Yuan 2016"
        ;;
    "-m")
        echo ${!MODULE[*]}
        exit 0
        ;;
    "-lt")
        check_module $2
        p=(${MODULE[$2]})
        echo ${p[0]}
        exit 0
        ;;
    "-lc")
        check_module $2
        p=(${MODULE[$2]})
        echo ${p[1]}
        exit 0
        ;;
    *)
        check_module $1
        test $1 $2 $3
        exit 0
        ;;
esac
